package com.bobi.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bobi.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 促销活动表(BobiPromotion)实体类
 *
 * @author makejava
 * @since 2023-07-02 16:30:09
 */
@Data
@TableName("bobi_promotion")
@AllArgsConstructor
@NoArgsConstructor
public class Promotion extends BaseEntity {
    private static final long serialVersionUID = -48193863351600031L;

    /**
     * 促销活动名称
     */

    private String promotionName;
    /**
     * 活动描述
     */
    private String description;
    /**
     * 活动开始时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;
    /**
     * 活动结束时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    public QueryWrapper<Promotion> initWrapper(Promotion promotion) {
        if(promotion.getId() != null || promotion.getPromotionName() != null) {
            QueryWrapper<Promotion> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq(StringUtils.isNotBlank(promotion.getId()), "id", promotion.getId());
            queryWrapper.eq(StringUtils.isNotBlank(promotion.getPromotionName()), "promotion_name" ,promotion.getPromotionName());
            return queryWrapper;
        }
        return null;
    }
}

